package com.zzq.mapper;

import com.zzq.pojo.TenderInfo;
import com.zzq.pojo.vo.FirstTenderInfo;
import com.zzq.pojo.vo.HotTenderInfo;
import com.zzq.pojo.vo.TenderInfoVO;
import com.zzq.pojo.vo.ViewCount;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

@Mapper
public interface TendererInfoMapper {

    @Update("update tender_info set hot_score=#{hotScore}, ` hot_update_time`=now() where tender_project_no=#{tenderProjectNo}")
    void updateHotScore(String tenderProjectNo, double hotScore);

    @Select("select * from tender_info where state!='待审核'")
    List<TenderInfo> list();

    @Select("select t.*,f.url from tender_info t,file_metadata f where t.state!='待审核' and t.tender_project_no=f.business_id")
    List<TenderInfoVO> all();


    @Select("select * from tender_info where state='待审核'")
    List<TenderInfo> some();

    @Update("update tender_info set state='投标' where tender_project_no=#{no}")
    void check(int no);

    @Delete("delete from tender_info where tender_project_no=#{no}")
    void elect(int no);

    List<TenderInfo> select(String manufacturer, String state);

    @Select("select * from tender_info where manufacturer=#{name} and state!='中标'")
    List<TenderInfo> selectByName(String name);

    @Insert("insert into tender_info values(#{tenderProjectNo},#{drugName},#{manufacturer},#{packagingReq},#{totalNumber},#{tenderDeadline},#{bidDeposit},#{state},now(),0,0,0,now())")
    void add(TenderInfo tenderInfo);

    @Update("update tender_info set drug_name=#{drugName},packaging_req=#{packagingReq},total_number=#{totalNumber},tender_deadline=#{tenderDeadline},bid_deposit=#{bidDeposit} where tender_project_no=#{tenderProjectNo}")
    void update(TenderInfo tenderInfo);

    @Update("update tender_info set state='中标' where tender_project_no=#{tenderProjectNo}")
    void updateStatus(String tenderProjectNo);

    List<TenderInfo> selectBid(String manufacturer);

    @Select("select manufacturer from tender_info where tender_project_no=#{no}")
    String getNameByNo(int no);

    @Select("select tender_project_no from tender_info where state = #{state} and tender_deadline < #{tenderIdTime}")
    List<String> getByStatusAndTendererTimeLT(String state, LocalDateTime tenderIdTime);

    @Update("update tender_info set state='已截至' where tender_project_no=#{tenderInfo}")
    void TendererTimeLTUpdateStatus(String tenderInfo);

    @Select("select bid_deposit from tender_info where tender_project_no=#{tenderProjectNo}")
    Double getBidDeposit(String tenderProjectNo);

    List<HotTenderInfo> getHotTenders(int page, int size);

    @Select("select tender_project_no,view_count from tender_info where tender_project_no=#{projectId}")
    ViewCount findViewCountById(String projectId);

    @Update("update tender_info set view_count=#{viewCount} where tender_project_no=#{tenderProjectNo}")
    void saveViewCount(ViewCount project);

    List<FirstTenderInfo> gitfirstHotTendererInfo(int page, int size);

    @Update("update tender_info set bidder_count=bidder_count+1 where tender_project_no=#{tenderProjectNo}")
    void addBidderCount(String tenderProjectNo);
}
